package minify;

import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.input.TransferMode;

import java.io.File;
import java.util.List;

/**
 * Created on 2015/7/15.
 *
 * @author Misty
 */
public class Utils {
    public static Scene config(Scene scene) {
        scene.setOnDragOver(event -> {
            List<File> files = event.getDragboard().getFiles();
            if (!files.isEmpty()) {
                File f = files.get(0);
                String n = f.getName().toLowerCase();
                if (n.endsWith(".js") || n.endsWith(".css")) {
                    event.acceptTransferModes(TransferMode.ANY);
                }
            }
        });
        scene.setOnDragDropped(event -> {
            File f = event.getDragboard().getFiles().get(0);
            TextField text = (TextField) scene.lookup("#s_input");
            text.setText(f.getPath());
            text.setUserData(f);
        });
        return scene;
    }
}
